package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.message.dto.SysAllowedJoinCompanyUserDTO;
import com.nineclock.model.dto.SysCompanyUserDTO;
import com.nineclock.model.pojo.SysCompanyUser;
import com.nineclock.system.SysCompanyUserControllerApi;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.ListResourceBundle;

@RestController
@RequestMapping("/companyUser")
public class SysCompanyUserController implements SysCompanyUserControllerApi {

    /**
     * 登录后选择企业了,根据企业id去查询,如果就一个企业就带会用户id,直接进入页面
     * 记得携带权限信息,后面鉴权,不是管理员不能登录
     * @param companyId 企业id
     * @param userId 员工id
     * @return
     */
    @Override
    @GetMapping("/query")
    public Result<List<SysCompanyUserDTO>> queryCompanyUser(
            @RequestParam(value = "companyId",required = false) Long companyId,
            @RequestParam(value = "userId",required = false) Long userId) {
        List<SysCompanyUserDTO> companyUserDTOS= companyUserService.queryCompanyUser(companyId,userId);

        return Result.success(companyUserDTOS);
    }

    //根据手机号获取企业员工信息
    @Override
    @GetMapping("/queryone")
    public Result<SysCompanyUserDTO> findCompanyUserByMobile(String mobile) {
        SysCompanyUserDTO companyUser = companyUserService.findCompanyUserByMobile(mobile);
        return Result.success(companyUser);
    }

    @Autowired
    SysCompanyUserService companyUserService;

    /**
     * 审核加入企业
     * @param sysAllowedJoinCompanyUserDTO
     * @return
     */

    @Override
    @PostMapping("/allowedJoinCompany")
    public Result allowedJoinCompany(@RequestBody SysAllowedJoinCompanyUserDTO sysAllowedJoinCompanyUserDTO) {
        companyUserService.allowedJoinCompany(sysAllowedJoinCompanyUserDTO);
        return Result.success();
    }

    /**
     * 考勤组列表获取所有企业员工信息
     * @return
     */
    @GetMapping("/members")
    List<SysCompanyUserDTO> queryAllCompanyUser(){
        List<SysCompanyUserDTO> sysCompanyUserDTOS = companyUserService.queryAllCompanyUser();
        return sysCompanyUserDTOS;
    }

    //根据企业ID查询企业的主管理员信息
    @GetMapping("/queryAdminByCompanyId")
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(Long companyId){
        SysCompanyUserDTO companyUserDTO = companyUserService.queryAdminByCompanyId(companyId);
        return Result.success(companyUserDTO);
    }
}
